<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8"/>
	<meta name="keywords" content="find,replace,replacement,regex,regular expression,batch"/>
	<link rel="stylesheet" href="../../Shared/sty/standard.css"/>
	<script defer src="../../Shared/js/toc.js"></script>
	
	<title>Replace text by multiple rules in CotEditor on Mac</title>
</head>

<body>
<a name="howto_multiple_replace"></a>

<h1>Replace text by multiple rules in CotEditor on Mac</h1>

<p>With the <dfn>Multiple Replace</dfn> feature, you can apply multiple text replacements at once in sequence. Each set of replacement rules can be saved as a named preset and reused whenever needed.</p>


<section>
<h2>Use Multiple Replace window</h2>

<p>Use the Multiple Replace window to manage and perform the multiple replacements in your document.</p>

<p>To open the Multiple Replace window:</p>
<ol>
	<li><p>Go to the CotEditor app <img class="appicon" srcset="../../Shared/gfx/icon_32x32@2x.png 2x" alt=""/> on your Mac.</p></li>
	<li><p>Choose Find &gt; Multiple Replace.</p></li>
</ol>

<p><img srcset="../gfx/multiple_replace_panel@2x.png 2x" alt="Screenshot of the Multiple Replace window"/></p>
</section>


<section>
<h2>Manage replacement definitions</h2>

<p>The stored replacement definitions you have created before appear in the list on the sidebar.</p>

<ul>
	<li><p>Click the Add button (+) at the bottom of the list to create a new definition.</p></li>
	<li><p>Click the Delete button (-) at the bottom of the list to delete the selected definition.</p></li>
	<li><p>Click the selected definition in the list again to rename it.</p></li>
	<li><p>Click the Action pop-up menu (<object type="image/svg+xml" class="symbol" data="../../Shared/gfx/ellipsis.circle.svg"></object>) for further operations.</p></li>
</ul>


<h3>Export/import replacement definitions</h3>

<p>You can export replacement definitions to transfer them to another computer.
Each definition is saved as a <dfn>CotEditor replace definition</dfn> file with the <code>.cotrpl</code> extension. The file content is written in JSON format.</p>

<ul>
	<li><p><em>Export</em>: Select a definition in the list, then choose Export or Share from the Action menu.</p></li>
	<li><p><em>Import</em>: Drop replacement definition files files into the list, or choose Import from the Action menu, then select the files to import.</p></li>
</ul>


<h3>Import TSV data as replacement definitions</h3>

<p>You can also create a replace definition from a UTF-8–encoded TSV file in which each line contains a pair of search and replacement texts separated by tabs. To import this format, choose a file with the .tsv extension using the Import command. In this format, you can’t specify options such as case sensitivity or enabling regular expressions. After importing a TSV file as a replace definition, configure any necessary options manually.</p>
</section>


<section>
<h2>Perform multiple replacements</h2>

<p>The definition selected in the list appears in the editor area on the right side. The replacement rules in the editor area are performed row by row from top to bottom at once.</p>

<p>Click the buttons below the editor area to perform multiple replacements.</p>

<ul>
	<li><p><em>Replace All</em>: Perform all replacements for the current document.</p></li>
	<li><p><em>Highlight</em>: Highlight all matches in the current document.</p></li>
</ul>

<p><em class="note">Note:</em> The matches highlighted by the Highlight command may differ from the actual replacement results because Replace All applies rules sequentially, and each rule is applied to the document after previous rules have already taken effect.</p>
</section>


<section>
<h2>Edit replacement definition</h2>

<p>You can create and customize your own replacement definitions.</p>


<h3>Create a new replacement definition</h3>

<ol>
	<li><p>Click the Add button (+) at the bottom of the list on the left side to create a new replacement definition.</p></li>
	<li><p>Click the Add button (+) in the editor area on the right side to create a new replacement rule.</p></li>
	<li><p>Enter your replacement rule in the added row.</p></li>
</ol>

<p>Your changes are saved automatically as you edit.</a>

<p>If a row contains an invalid rule, it is skipped when performing the replacement.</p>


<h3>Replacement rule options</h3>

<table>
	<thead>
		<tr><th>Option</th><th>Description</th></tr>
	</thead>
	<tbody>
		<tr><th>(checkbox)</th><td>If the checkbox is unselected, the row is just skipped. You can use this option to keep a replacement rule that is used depending on the situation.</td></tr>
		<tr><th>Find</th><td>The text to search for. This field cannot be left empty. If empty, the rule is considered invalid and skipped.</td></tr>
		<tr><th>Replace With</th><td>The text to replace with. If left empty, the matched text is removed.</td></tr>
		<tr><td>RE</td><td>Search using a regular expression (abbreviation of <u>R</u>egular <u>E</u>xpression).</td></tr>
		<tr><td>IC</td><td>Ignore case when searching (abbreviation of <u>I</u>gnore <u>C</u>ase).</td></tr>
		<tr><th>Description</th><td>You can use this field to leave a comment about the rule. The description doesn’t affect to replacement. This field can be left blank.</td></tr>
	</tbody>
</table>
</section>


<section>
<h2>Change advanced find options</h2>

<p>You can fine-tune the find behavior for the entire replacement definition in the Advanced options view. Those settings are also saved to your definition and apply to all rules within the definition.</p>

<p>Click the gear button in the Multiple Replace window, then click checkboxes as needed.</p>

<p>For details on each setting, see <a href="howto_find.html">Find or replace text</a>.</p>
</section>


<section id="cf">
<h2>See also</h2>
<ul>
	<li><a href="howto_find.html">Find or replace text in CotEditor on Mac</a></li>
	<li><a href="about_regex.html">Use the regular expression in CotEditor on Mac</a></li>
</ul>
</section>

</body>
</html>
